package com.aaa.config.swaggerconfig;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * -*- coding:utf-8 -*-
 *
 * @author 太阳偷渡青山
 * @software IntelliJ IDEA
 * @date 2022/11/18 9:59
 * @Description
 */
@Configuration
public class SwaggerConfig {

    @Autowired
    private SwaggerProperties swagger;

    @Bean
    public Docket createRestApi() {
        String version = "3.X版本";
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title(swagger.getTitle())
                        .description(swagger.getDescription())
                        .termsOfServiceUrl(swagger.getTermsOfServiceUrl())
                        .contact(new Contact(swagger.getName(), swagger.getTermsOfServiceUrl(), swagger.getEmail()))
                        .version(version)
                        .build())
                //分组名称
                .groupName(swagger.getGroupName())
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage(swagger.getBasePackage()))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
